//
// knlvar.cpp
// Usage: Declare global kernel var
// Create Date: 2008-02-14
// Creator: MaJiuyue
//
#include <NewLife.h>
#include "Multiboot.h"
#include "protect.h"
#include "knlvar.h"
#include "../schedule/Process.h"

// Range of low memory
u32 LOWMEM_START;
u32 LOWMEM_END;

// Kernel end phyiscal address
addr_t KERNEL_END;

// Kernel reserved memory for self
addr_t KERNEL_RESERVED_START;
addr_t KERNEL_RESERVED_END; 

// Kernel physical memory map end 
addr_t PHYMAP_END;

// Range of VM
addr_t VMALLOC_START;
addr_t VMALLOC_END;

// Temporary kernel map base address
addr_t TKMAP_BASE;

// Persistent kernel map base address
addr_t PKMAP_BASE;

// Fix map base address
addr_t FIXADDR_BASE;

// Array of module
addr_t mods_addr;
// Count of module
int mods_count;

// Boot device
u32 boot_dev;

// Global PageDirectory
// kernel_pdt is defined at `linker.ld', address 0x100000
extern char kernel_pdt;
pde_t * KernelPDT = (pde_t *)&kernel_pdt;

/* Task Status Segment */
struct TSS tss;

/* Descriptor for GDT */
DESCRIPTOR GDT[GDT_SIZE] = {
	MAKE_DESCRIPTOR(        0x0,     0x0,                      0x0),
	MAKE_DESCRIPTOR( 0xC0000000, 0x3FFFF,  DA_CR|DA_32|DA_LIMIT_4K),
	MAKE_DESCRIPTOR( 0xC0000000, 0x3FFFF, DA_DRW|DA_32|DA_LIMIT_4K),
	MAKE_DESCRIPTOR(        0x0, 0xFFFFF, DA_DRW|DA_32|DA_LIMIT_4K),
	MAKE_DESCRIPTOR( vir2lin((u32)&tss) , sizeof(TSS)-1, DA_386TSS),
	MAKE_DESCRIPTOR(	0x0,	 0x0,			   0x0),
	MAKE_DESCRIPTOR(	0x0, 0xBFFFF,  DA_CR|DA_32|DA_LIMIT_4K)
};
GDTPointer GdtPtr = { 
	sizeof(DESCRIPTOR)*GDT_SIZE-1,      /* GDT limit */
	vir2lin((u32)GDT)                   /* GDT base high */
};

